package com.scs.application.modules.dept.service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.scs.application.core.query.QueryContext;
import com.scs.application.core.service.IBaseService;
import com.scs.application.modules.base.entity.Dept;
import com.scs.application.modules.dept.dto.ApplyItemVo;
import com.scs.application.modules.dept.entity.ApplyAuto;
import com.scs.application.modules.wm.entity.Dist;
import com.scs.application.modules.wm.entity.Transfer;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * <p>
 * Service
 * </p>
 */

public interface ApplyAutoService extends IBaseService<ApplyAuto> {


    /**
     * PDA 查询所有待响应的 数据
     */
    List<ApplyAuto> listApplyAutoPDA(ApplyAuto applyAuto);

    /**
     * 产生自动请领单
     */
    String autoCreateApply();


    /**
     * 创建单个自动请领单
     */
    void createSingleApply(String warehouseId, String matrId);
    /**
     * 创建多个自动请领单
     */
    void createMultipleApply(String warehouseId, List<String> matrIds);
    /**
     * 转调拨单
     *
     * @param applyAutos
     * @return
     */
    List<Transfer> toTransfer(List<ApplyAuto> applyAutos);

    List<Dist> toDist(List<ApplyItemVo> applyAutos, String targetStatus);

    /**
     *
     * @param idList -1: dept_auto_apply.id 集合
     *               1: purchase_order.id 集合
     * @param type -1:重置关联需求在途数量和关联单号
     *             1:更新关联需求在途数量和关联单号
     * @Description： 更新/重置在途数量和关联单号
     */
    void updateApplyInfo(List<String> idList,int type);

    void respondClose(List<ApplyAuto> applyAutos,String remark);

    List<Dept> autoApplyDeptList(QueryContext queryContext);

    List<Dept> autoTransferDeptList(QueryContext queryContext);

    IPage pageForTransfer(QueryContext queryContext);

//  整单据作废
    @Deprecated
    boolean close(String id, String remark);
//  明细作废
    @Deprecated
    boolean closeItem(String id, String remark);

    @Transactional(rollbackFor = Exception.class)
    List<ApplyAuto> listWithHistory(QueryWrapper<ApplyAuto> wrapper);

    /**
     * 计算期间内的请领金额
     * @param startDate
     * @param endDate
     * @return
     */
    Double getSumAmount(String startDate, String endDate);
    /**
     * 自动填充开单数量
     * @param applyAutos
     * @return
     */
    String fillQty(List<ApplyAuto> applyAutos);
}
